require 'andand'
require 'util'
require 'table'

class BalanceSheet < ActiveRecord::Base
	@@cn2en = {
		'报告期'=>'report_date',
    
		'货币资金'=>'cash',
		'短期投资'=>'short_term_investments',
		'短期投资跌价准备'=>'short_term_investments_falling_price_reserve',
		'短期投资净额'=>'net_bal_of_current_investment',
		'应收票据'=>'notes_receivable',
		'应收股利'=>'dividends_receivable',
		'应收帐款'=>'account_receivable',
		'应收账款净额'=>'net_bal_of_account_receivable',
		'其他应收款'=>'receivable_other',
		'其他应收款净额'=>'net_bal_of_receivable_other',
		'内部应收款'=>'internal_account_receivable',
		'坏帐准备'=>'provision_for_bad_debts',
		'应收款项净额'=>'net_bal_of_receivable',
		'预付帐款'=>'accounts_prepaid',
		'其它补贴款'=>'other_allowance',
		'存货'=>'inventory',
		'存货跌价准备'=>'inventory_falling_price_reserves',
		'存货净额'=>'net_bal_of_inventory',
		'待摊费用'=>'deferred_expenses',
		'待处理流动资产净损失'=>'net_loss_of_current_assets_to_be_settled',
		'一年内到期的长期债权投资'=>'long_term_debt_investment_due_within_one_year',
		'其它流动资产'=>'other_current_assets',
		'附属企业往来'=>'branch_cash_flow',
		'内部往来'=>'internal_cash_flow',
		'流动资产合计'=>'total_current_assets',
		'长期股权投资'=>'long_term_equity_investment',
		'长期债权投资'=>'long_term_debt_investment',
		'其他长期投资'=>'other_long_term_investment',
		'长期投资合计'=>'total_long_term_investment',
		'长期投资减值准备'=>'provision_for_long_term_investment',
		'长期投资净额'=>'net_bal_of_long_term_investment',
		'合并价差'=>'cost_book_value_differentials',
		'股权投资差额'=>'equity_investment_difference',
		'固定资产原价'=>'fixed_assets_cost',
		'累计折旧'=>'accumulated_depreciation',
		'固定资产净值'=>'net_value_of_fixed_assets',
		'固定资产减值准备'=>'fixed_assets_depreciation_reserves',
		'固定资产净额'=>'net_value_of_fixed_assets',
		'工程物资'=>'project_material',
		'在建工程'=>'construction_in_progress',
		'在建工程减值准备'=>'impairment_of_construction_in_progress',
		'在建工程净额'=>'net_bal_of_construction_in_progress',
		'待处理固定资产净损失'=>'net_loss_of_fixed_assets_to_be_settled',
		'固定资产清理'=>'disposal_of_fixed_assets',
		'固定资产合计'=>'total_fixed_assets',
		'无形资产'=>'intangible_assets',
		'开办费'=>'front_end_fees',
		'递延资产'=>'defer_assets',
		'长期待摊费用'=>'long_term_deferred_expenses',
		'其他长期资产'=>'other_long_term_assets',
		'无形资产及其他资产合计'=>'total_intangible_assets_and_other_assets',
		'递延税项借项'=>'deferred_assets_debits',
		'资产总计'=>'total_assets',
		'短期借款'=>'short_loan',
		'应付票据'=>'notes_payable',
		'应付帐款'=>'account_payable',
		'预收帐款'=>'adanvances_from_customers',
		'代销商品款'=>'consignor_payable',
		'应付工资'=>'wages_payable',
		'应付福利费'=>'welfare_payable',
		'应付股利'=>'dividends_payable',
		'应交税金'=>'taxes_payable',
		'其他应交款'=>'other_payable_to_gov',
		'其他应付款'=>'other_payable',
		'预提费用'=>'provision_for_expenses',
		'预计负债'=>'accrued_liabilities',
		'一年内到期的长期负债'=>'long_term_liabilities_due_within_one_year',
		'其他流动负债'=>'other_current_liabilities',
		'职工奖励及福利基金'=>'bonus_and_allowance_bond',
		'国内票据结算'=>'bill_for_clearing',
		'流动负债合计'=>'net_bal_of_current_liabilities',
		'长期借款'=>'long_term_loans',
		'应付债券'=>'bonds_payable',
		'长期应付款'=>'long_term_payables',
		'住房周转金'=>'housing_revolving_funds',
		'专项应付款'=>'specific_payable',
		'其他长期负债'=>'other_long_term_debt',
		'长期负债合计'=>'total_long_term_liabilities',
		'递延税项贷项'=>'deferred_taxation_credit',
		'负债合计'=>'total_liabilities',
		'少数股东权益'=>'minority_equity',
		'股本'=>'capital',
		'已归还投资'=>'retired_capital',
		'股本净额'=>'net_bal_of_paid_in_capital',
		'资本公积金'=>'capital_reserve',
		'盈余公积金'=>'surplus_accumulation_fund',
		'公益金'=>'public_welfare_fund',
		'未确认的投资损失'=>'not_confirmed_investment_losses',
		'未分配利润'=>'undistributed_profit',
		'货币换算差额'=>'currency_translation_difference',
		'股东权益合计'=>'total_shareholders_equity',
		'负债及股东权益总计'=>'total_debt_and_equity'
  }
  @@en2cn = {}

	def self.cn2en
		@@cn2en
	end

  def self.en2cn
    if @@en2cn.empty?
      @@cn2en.each { |key, value| @@en2cn[value] = key }
    end
    @@en2cn
  end

	def self.find_by_stock_no_from_sina(stock_no)
		return Util.find_data_by_from_sina(
			"http://money.finance.sina.com.cn/corp/go.php/vFD_BalanceSheet/stockid/#{stock_no}/ctrl/part.phtml",
			'BalanceSheetNewTable',
			@@cn2en
		)
		
  end
end
